<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<style>
.ke-icon-imwebs {
	background-image: url(text/lib/kindeditor/themes/common/webs.png);
	background-position: 0px 0px;
	width: 16px;
	height: 16px;
}
</style>
<div class="modal fade" role="dialog" id="modelWebInWindow"
	style="z-index: 999">
	<div class="modal-dialog" role="document" style="margin-top: 100px;">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" style="font-weight: 700">解析网页并插入编辑器</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<input id="wcp_webin_urlId" type="text" class="form-control"
						placeholder="http://..."> <span class="input-group-btn">
						<button id="EditorWebLinkSubmitButtonId" class="btn btn-info"
							type="button">
							<span id="EditorWebLinkSubmitButtonTitleId">解析并插入编辑器</span><span
								id="EditorWebLinkSubmitButtonGraphaId">1</span>
						</button>
					</span>
				</div>
				<div>
					<span id="EditorWebLinkErrorId"></span>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default"
					onclick="$('#modelWebInWindow').modal('hide')">关闭</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<script>
	$(function() {
		$('#EditorWebLinkSubmitButtonId').bind('click', function() {
			if (!checkUnit($('#wcp_webin_urlId'))) {
				//$('#EditorWebLinkErrorId').text('信息录入有误，请检查！');
			} else {
				submitWebUrlWaitBackHtml($('#wcp_webin_urlId').val())
			}
		});
		validateInput('wcp_webin_urlId', function(id, val, obj) {
			if (valid_isNull(val)) {
				return {
					valid : false,
					msg : '不能为空'
				};
			}
			if (!valid_isUri(val)) {
				return {
					valid : false,
					msg : '请检URL地址格式'
				};
			}
			return {
				valid : true,
				msg : '正确'
			};
		}, 'EditorWebLinkErrorId');
		setInterval(function() {
			$('#EditorWebLinkSubmitButtonGraphaId').text(parseInt($('#EditorWebLinkSubmitButtonGraphaId').text())+1);
		}, 1000);
		$('#EditorWebLinkSubmitButtonGraphaId').hide();
	});

	// 自定义插件 #1
	KindEditor.lang({
		imwebs : '载入网页'
	});
	KindEditor.plugin('imwebs', function(K) {
		var self = this, name = 'imwebs';
		self.clickToolbar(name, function() {
			$('#modelWebInWindow').modal({
				keyboard : false,
				backdrop : false
			})
		});
	});

	//解析word文件并返回html
	function submitWebUrlWaitBackHtml(url) {
		$('#EditorWebLinkSubmitButtonId').addClass("disabled");
		$('#EditorWebLinkSubmitButtonTitleId').text("解析中...");
		$('#EditorWebLinkSubmitButtonGraphaId').show();
		$('#EditorWebLinkSubmitButtonGraphaId').text('0');
		$.post('know/webToHtml.do', {
			'url' : url
		}, function(flag) {
			$('#EditorWebLinkSubmitButtonGraphaId').hide();
			$('#EditorWebLinkSubmitButtonId').removeClass("disabled");
			$('#EditorWebLinkSubmitButtonTitleId').text("解析网页并插入编辑器");
			if (flag.STATE == 1) {
				alert(flag.MESSAGE)
			} else {
				try {
					editor.focus();
					editor.insertHtml(" ");
				} catch (e) {
					editor.appendHtml(" ")
				}
				try {
					editor.insertHtml(flag.HTML);
				} catch (e) {
				}
				$('#modelWebInWindow').modal('hide');
			}
			$('#wcp_webin_urlId').val("")
		}, 'json');
	}
</script>